<?php
/**
 * File: profile.php
 * 
 * Displays the user's peronal iHacky profile.
 */
/**
 * 
 */
// including necessary database and facebook files.
include 'lib/config.php';
require_once 'lib/mockajaxfbconfig.php';
include 'iHackyFunctions.php';

if(isset($_REQUEST['Username'])) {
    
    $conn = getDbConn();

    // grabs data from HTTP POST by corresponding variable.
    $hackystat_id = $_REQUEST['Username'];
    $hackystat_password = $_REQUEST['Password'];
    $facebook_id = $user;
   
    $hackystatCouplingURL = "http://dasha.ics.hawaii.edu:9876/sensorbase/".
                        "sensordata/".$hackystat_id."?sdt=Coupling";
   
    if(testLogin($hackystatCouplingURL, $hackystat_id, $hackystat_password)) {
      // SQL query to inserts new account to the database.
      $queryEditHackystatInfo = "UPDATE USERS SET hackystat_id = '$hackystat_id', 
          hackystat_password = AES_ENCRYPT('$hackystat_password','414')
          WHERE USERS.facebook_id = $facebook_id";
             
      // invoke the SQL query, prints error if errors out.
      mysql_query($queryEditHackystatInfo, $conn) or DIE(mysql_error());
    
      echo "<br> Hackystat information updated. <br><br>";
      closeDb($conn);
    }
    else {
        echo "<b><font color=\"#FF0000\">Username or Password<br>not valid!
            </font></b><br>
            <img src=\"http://www.ikoaguild.com/ihacky/images/problemIcon.png\"> 
            <br>Click here to <a href=\"profile.php\">Retry</a><br>";
    }  
    exit;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.header {
    background: #D8DFEA none repeat scroll 0%;
    border-top: 1px solid #3b5998;
    margin: 0px;
    padding: 2px 8px;
}

.tag_cloud { padding: 3px; text-decoration: none; }
.tag_cloud:link  { color: #3B5998; }
.tag_cloud:visited { color: #3B5998; }
.tag_cloud:hover { color: #ffffff; background: #3B5998; }
.tag_cloud:active { color: #ffffff; background: #3B5998; }
</style>

<!-- <title>iHacky</title> -->
</head>

<?php
printJavaScriptDiv();
printTitle();
printDashboard();
printBanner($user);
printFbmlTabs(2);

editHackystatInfo();
echo '<span style="display:none"><fb:editor></fb:editor></span>
<form id="search_form">
<table class="editorkit" border="0" cellspacing="0" style="width:100px">
<tr class="width_setter">
<td class="editorkit_row">
<input type="hidden" name="userClassesInput" value="dummy"/> 
</td>
<td class="editorkit_buttonset">
 <input type="submit" class="editorkit_button action" value="List All Your Classes"  
              clickrewriteurl="http://www.ikoaguild.com/ihacky/rank_change.php"
              clickrewriteform="search_form" 
              clickrewriteid="content"
              clicktoshow="loadIcon"/>
</td>
</tr>
</table>
</form>
<div id="content">
   <div align="center">
     <img src="http://www.ikoaguild.com/ihacky/images/ajax-loader.gif" id="loadIcon"
        style="display:none;" />  
   </div>
</div>';

?>